/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSAUTORES;

import Entidades.EntidadesAutores.Articuloalumno;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author LUIGI
 */
@Stateless
@LocalBean
public class ArticuloalumnoDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    EntityManager em;
    public void crear(Articuloalumno al) {
        em.persist(al);
    }

    public void actualizar(Articuloalumno al) {
        em.merge(al);
    }

    public void borrar(Integer id) {
        Articuloalumno artialu = em.find(Articuloalumno.class, id);
        em.remove(artialu);
    }

    public void guardar(Articuloalumno al) {
        if (al.getIdArticuloAlumno() == null) {
            crear(al);
        } else {
            actualizar(al);
        }
    }

    public List<Articuloalumno> BuscarTodosArticuloalumno() {
        return em.createNamedQuery("Articuloalumno.findAll", Articuloalumno.class).getResultList();
    }

    public List<Articuloalumno> BuscarArticuloalumno(String cadena) {
        return em.createNamedQuery("Articuloalumno.findByIdArticuloAlumno", Articuloalumno.class)
                .setParameter("articulo alumno", cadena).getResultList();
    }
    
}
